package com.example.myapplication.view;

import android.content.Context;
import android.util.DisplayMetrics;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.LinearSmoothScroller;
import androidx.recyclerview.widget.RecyclerView;

@SuppressWarnings("ALL")
public class PullRefreshViewLManager extends LinearLayoutManager {

    private boolean isAnim = false;

    public PullRefreshViewLManager(Context context) {
        super(context);
    }

    @Override
    public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
        LinearSmoothScroller linearSmoothScroller = null;
        if (isAnim) {
            linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {
                @Override
                protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
                    return 150f / displayMetrics.densityDpi;
                }
            };
        } else {
            linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext());
        }
        linearSmoothScroller.setTargetPosition(position);
        startSmoothScroll(linearSmoothScroller);
    }

    public boolean isAnim() {

        return isAnim;

    }

    public void setAnim(boolean anim) {

        isAnim = anim;

    }

}
